package com.wuba.rxjavademo.tzx.merge;

import com.wuba.rxjavademo.tzx.common.Base;

import java.util.concurrent.TimeUnit;

import rx.Observable;
import rx.functions.Func1;
import rx.functions.Func2;

/**
 * Created by tanzhenxing
 * Date: 2016/6/28.
 * Description:
 */
public class RxJoin extends Base {
    public static void main(String[] args) throws InterruptedException {
        RxJoin join = new RxJoin();
        join.run();
        Thread.sleep(90);
    }

    @Override
    public void run() {
        Observable<Integer> apps = Observable.interval(1, TimeUnit.MILLISECONDS)
                                            .map(aLong -> Integer.valueOf((int) (aLong * 100)));

        Observable<Long> tictoc = Observable.interval(1, TimeUnit.MILLISECONDS);

        apps.join(
                tictoc,
                app -> Observable.timer(2, TimeUnit.MILLISECONDS),
                time -> Observable.timer(0, TimeUnit.MILLISECONDS),
                (aint, aLong) -> Integer.valueOf((int)(aLong * aint + 100000))
                )
                .subscribe(Base::print);
    }
}
